<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    <input type="button" value="按钮" id="btn">
    <script>
        var btn = document.getElementById("btn")
        function addEvent(ele, type, fn) {
            if (ele.addEventListener) {
                ele.addEventListener(type, fn)
            }
            else if (ele.attachEvent) {
                ele.attachEvent("on" + type, fn)
            }
            else {
                ele["on" + type] = fn
            }
        }

        addEvent(btn, "click", function () {
            var hd3 = document.createElement("h3")
            hd3.innerText = "事件绑定成功"
            document.body.appendChild(hd3)
        })
    </script>

</body>

</html>